"""
A class to exercise the JT core functions.
"""
import vtk
import JT2 as JT
import Calibration
from numpy import array, zeros, asarray
import time
def Test():
    """
    Test the volume rendering implemented in JT
    """
#===============================================================================
#    Data Paths
#===============================================================================
    inputVolFileName = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1.mha'
    maskFileName = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1b2VOI.mha'
    staFile = 'C:/Users/bryan/bryan-code/2D3D/vert1/CT/ucharCTv1r1.sta'
    calFile = 'C:/Users/bryan/bryan-code/trunk/TestData/ext_cal1.txt'
    startPositionsPath = 'C:/Users/bryan/bryan-code/2D3D/startpositions_200_ordered.txt'
    
    #===============================================================================
    #    Generate Lateral Projection
    #===============================================================================
    xraycam = JT.XRayCamera()
    drr = JT.DRR()
    
    drr.SetXRayCamera(xraycam)
    drr.SetBlackOnWhiteImage()
    drr.InteractionOff()
    
    #===============================================================================
    #    Calibration
    #===============================================================================
    cal = Calibration.ExternalCalibration()
    cal.LoadConsolidatedCalibration(calFile)
    cal.LoadStaFile(staFile)
    
    xraycam.SetExternalCalibration(cal)
    
    volume1 = JT.Volume()
    drr.AddVolume(volume1)
    volume1.SetVolumeFilename(inputVolFileName)
    volume1.SetOriginalTransform(cal._VolumeT)
    volume1.SetBodyCenter((3.906, 2.17, -7.378))
    volume1.SetImageMask(maskFileName)
    
    drr._renWin.SetOffScreenRendering(0)

    T = JT.Testing()
    for ii in range(200):
        volume1.SetPose(T.GetStartPose(ii))
        drr.Render()
        t1=time.time()
#        drr.SaveGeneratedImage(
#            'C:/Users/bryan/bryan-code/trunk/Images/StartPoses/startpose_%i.jpg' % (ii))
        print "image %i saved (%f)!" % (ii,time.time()-t1)
        ii += 1

if __name__ == "__main__":
    Test()